<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 6.3.0">
<link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300italic,400,400italic,700,700italic%7CZCOOL+QingKe+HuangYou:300,300italic,400,400italic,700,700italic%7CNoto+Sans+Simplified+Chinese:300,300italic,400,400italic,700,700italic%7CJetBrains+Mono:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="/lib/@fortawesome/fontawesome-free/css/all.min.css" integrity="sha256-HtsXJanqjKTc8vVQjO4YMhiqFoXkfBsjBWcX91T1jr8=" crossorigin="anonymous">
  <link rel="stylesheet" href="/lib/animate.css/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="/lib/@fancyapps/ui/dist/fancybox/fancybox.css" integrity="sha256-RvRHGSuWAxZpXKV9lLDt2e+rZ+btzn48Wp4ueS3NZKs=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"wyatex.online","root":"/","images":"/images","scheme":"Pisces","darkmode":true,"version":"8.18.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":false,"height":500},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":true}}</script><script src="/js/config.js"></script>

    <meta name="description" content="在学习C语言之前我们先来了解一下一个程序应该包括哪些内容。">
<meta property="og:type" content="article">
<meta property="og:title" content="简单易懂的C语言-3">
<meta property="og:url" content="https://wyatex.online/C%E8%AF%AD%E8%A8%80/C-language-learn-3/index.html">
<meta property="og:site_name" content="Wyatex&#96;s blog">
<meta property="og:description" content="在学习C语言之前我们先来了解一下一个程序应该包括哪些内容。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-10-04T13:01:01.000Z">
<meta property="article:modified_time" content="2023-05-05T01:25:47.020Z">
<meta property="article:author" content="Wyatex">
<meta property="article:tag" content="教程">
<meta property="article:tag" content="C语言">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://wyatex.online/C%E8%AF%AD%E8%A8%80/C-language-learn-3/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://wyatex.online/C%E8%AF%AD%E8%A8%80/C-language-learn-3/","path":"C语言/C-language-learn-3/","title":"简单易懂的C语言-3"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>简单易懂的C语言-3 | Wyatex`s blog</title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">Wyatex`s blog</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">97</span></a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">26</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">155</span></a></li><li class="menu-item menu-item-编程"><a href="/programming/" rel="section"><i class="fa fa-book fa-fw"></i>编程</a></li><li class="menu-item menu-item-蹲坑读物"><a href="/%E5%B9%B2%E8%B4%A7/%E5%BC%80%E5%8F%91%E4%BA%A4%E6%B5%81%E7%BE%A4%E5%88%86%E4%BA%AB%E8%AE%B0%E5%BD%95/" rel="section"><i class="fa fa-book fa-fw"></i>蹲坑读物</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#C%E8%AF%AD%E8%A8%80%E7%9A%84%E7%BB%93%E6%9E%84"><span class="nav-number">1.</span> <span class="nav-text">C语言的结构</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AF%AD%E5%8F%A5%E7%9A%84%E7%BB%93%E6%9E%84"><span class="nav-number">1.1.</span> <span class="nav-text">语句的结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B3%A8%E9%87%8A"><span class="nav-number">1.2.</span> <span class="nav-text">注释</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A0%87%E8%AF%86%E7%AC%A6"><span class="nav-number">1.3.</span> <span class="nav-text">标识符</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%A7%84%E8%8C%83%E6%8C%87%EF%BC%9A"><span class="nav-number">1.3.1.</span> <span class="nav-text">规范指：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%91%BD%E5%90%8D%E6%96%B9%E6%B3%95%EF%BC%9A"><span class="nav-number">1.3.2.</span> <span class="nav-text">命名方法：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%91%BD%E5%90%8D%E8%A7%84%E8%8C%83%E8%A1%A5%E5%85%85"><span class="nav-number">1.3.3.</span> <span class="nav-text">命名规范补充</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%A9%BA%E6%A0%BC%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="nav-number">1.4.</span> <span class="nav-text">空格的使用</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="nav-number">2.</span> <span class="nav-text">数据类型</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%95%B4%E6%95%B0%E7%B1%BB%E5%9E%8B"><span class="nav-number">2.1.</span> <span class="nav-text">整数类型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B5%AE%E7%82%B9%E7%B1%BB%E5%9E%8B"><span class="nav-number">2.2.</span> <span class="nav-text">浮点类型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#void%E7%B1%BB%E5%9E%8B"><span class="nav-number">2.3.</span> <span class="nav-text">void类型</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%8F%98%E9%87%8F%E5%92%8C%E5%B8%B8%E9%87%8F"><span class="nav-number">3.</span> <span class="nav-text">变量和常量</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-number">4.</span> <span class="nav-text">运算符</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-number">4.1.</span> <span class="nav-text">算术运算符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%85%B3%E7%B3%BB%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-number">4.2.</span> <span class="nav-text">关系运算符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%80%BB%E8%BE%91%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-number">4.3.</span> <span class="nav-text">逻辑运算符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%B5%8B%E5%80%BC%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-number">4.4.</span> <span class="nav-text">赋值运算符</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%AC%AC%E4%B8%89%E7%AB%A0%E7%9A%84%E6%80%9D%E8%80%83%E9%A2%98%EF%BC%9A"><span class="nav-number">5.</span> <span class="nav-text">第三章的思考题：</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Wyatex"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Wyatex</p>
  <div class="site-description" itemprop="description">这里是我用来做笔记的网站哟~</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">155</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">26</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">97</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/wyatex" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wyatex" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:wyatex@qq.com" title="E-Mail → mailto:wyatex@qq.com" rel="noopener me" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
    <div class="sidebar-inner sidebar-blogroll">
      <div class="links-of-blogroll animated">
        <div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
          链接
        </div>
        <ul class="links-of-blogroll-list">
            <li class="links-of-blogroll-item">
              <a href="https://antfu.me/" title="https:&#x2F;&#x2F;antfu.me&#x2F;" rel="noopener" target="_blank">Anthony Fu</a>
            </li>
            <li class="links-of-blogroll-item">
              <a href="https://www.codesky.me/" title="https:&#x2F;&#x2F;www.codesky.me&#x2F;" rel="noopener" target="_blank">CodeSky</a>
            </li>
            <li class="links-of-blogroll-item">
              <a href="https://learn.lianglianglee.com/" title="https:&#x2F;&#x2F;learn.lianglianglee.com&#x2F;" rel="noopener" target="_blank">技术文章摘抄</a>
            </li>
        </ul>
      </div>
    </div>
        <div class="pjax">
        <div class="sidebar-inner sidebar-post-related">
          <div class="animated">
              <div class="links-of-blogroll-title"><i class="fa fa-signs-post fa-fw"></i>
    相关文章
  </div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/uncategorized/JsonSchema%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" rel="bookmark">
        <time class="popular-posts-time">2021-10-19</time>
        <br>
      JsonSchema学习笔记
      </a>
    </li>
  </ul>

          </div>
        </div>
        </div>
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wyatex.online/C%E8%AF%AD%E8%A8%80/C-language-learn-3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Wyatex">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Wyatex`s blog">
      <meta itemprop="description" content="这里是我用来做笔记的网站哟~">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="简单易懂的C语言-3 | Wyatex`s blog">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          简单易懂的C语言-3
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-10-04 21:01:01" itemprop="dateCreated datePublished" datetime="2019-10-04T21:01:01+08:00">2019-10-04</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-05-05 09:25:47" itemprop="dateModified" datetime="2023-05-05T09:25:47+08:00">2023-05-05</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/C%E8%AF%AD%E8%A8%80/" itemprop="url" rel="index"><span itemprop="name">C语言</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><blockquote>
<p>在学习C语言之前我们先来了解一下一个程序应该包括哪些内容。</p>
</blockquote>
<span id="more"></span>
<h1 id="C语言的结构"><a href="#C语言的结构" class="headerlink" title="C语言的结构"></a>C语言的结构</h1><p>C语言主要包括下面这几个内容：</p>
<ul>
<li><p>预处理器指令</p>
</li>
<li><p>函数</p>
</li>
<li><p>变量</p>
</li>
<li><p>语句（语句块）和表达式</p>
</li>
<li><p>注释<br>我们看回上一节的代码</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;HelloWorld!&quot;</span>);		<span class="comment">//打印HelloWorld</span></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>第一行的 <code>#include&lt;stdio.h&gt;</code> 叫做预处理器指令，用途就是在编译的时候加入这个stdio.h文件里的内容。</p>
</li>
<li><p>到下两行的<code>int main()</code>，这里的main指这个函数是主函数，程序都需要从主函数开始，没有写C语言程序一定要有主函数，不然就运行不起来。而main前面的int指这个函数是int类型，类型后面说到。</p>
</li>
<li><p>第五行有两个部分，一个是<code>printf(&quot;HelloWorld!&quot;);</code>和<code>//打印HelloWorld</code>，printf()是在stdio.h中写好的函数，用来在命令行中打印各种字符（不要忘记后面的“；”哦，没写“；”是会报错的）。右边还有一句<code>//打印HelloWorld</code>，主要内容是“&#x2F;&#x2F;”，从双斜杠开始，后面的任何字符都会被编译器无视，后面写的任何内容将不会出现在编译好的程序里。</p>
</li>
<li><p>下一行的<code>return 0;</code>,这句话代表了这个函数的结束，并返回0，所以就算你下面还有其他语句，也不会执行，因为一旦这个函数执行了return语句就会立刻结束。</p>
</li>
</ul>
<p>如果看完上一节我相信你也掌握了编译的技巧了，如果还不懂就复习一下前面的内容。</p>
<h2 id="语句的结构"><a href="#语句的结构" class="headerlink" title="语句的结构"></a>语句的结构</h2><p>这里用上面的<code>printf(&quot;HelloWorld!&quot;);</code>来说，这是一个语句，它应该包括五部分：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">printf</span><br><span class="line">(</span><br><span class="line">&quot;HelloWorld!&quot;</span><br><span class="line">)</span><br><span class="line">;</span><br></pre></td></tr></table></figure>
<p>而<code>return 0;</code>可以看成</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">return</span><br><span class="line">0</span><br><span class="line">;</span><br></pre></td></tr></table></figure>
<p>从两个例子可以看出所有的语句结束时均要加上；不然会报错，而函数后面均要使用()，括号里面的内容是你要传入的内容，比如printf函数输入”Fuck”就可以在命令行打印出Fuck。</p>
<h2 id="注释"><a href="#注释" class="headerlink" title="注释"></a>注释</h2><p>上面讲到了单行注释&#x2F;&#x2F;，其实还有一个多行注释，用法是</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">/*  </span><br><span class="line">    窝窝头</span><br><span class="line">    一块钱四个</span><br><span class="line">    嘿嘿</span><br><span class="line">*/</span><br></pre></td></tr></table></figure>
<p>相当于</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">//</span><br><span class="line">//  窝窝头</span><br><span class="line">//  一块钱四个</span><br><span class="line">//  嘿嘿</span><br><span class="line">//</span><br></pre></td></tr></table></figure>
<p>当然<code>//记得双击么么哒</code>也相当于<code>/* 记得双击么么哒 */</code></p>
<p>你喜欢怎么用就看你了。</p>
<h2 id="标识符"><a href="#标识符" class="headerlink" title="标识符"></a>标识符</h2><p>标识符用于给函数、变量、常量等注入灵魂（指命名），但是命名要遵循规范哦，不然也会报错，最好按照一种命名方法进行命名不然恶心到的是自己或者下一个接手这个项目的人。</p>
<h3 id="规范指："><a href="#规范指：" class="headerlink" title="规范指："></a>规范指：</h3><p>一个标识符以字母 A-Z 或 a-z 或下划线 _ 开始，后跟零个或多个字母、下划线和数字（0-9）。C语言是区分大小写的语言所以需要注意一下，比如awsl和AWSL是不一样的哦，OI和0l也是不一样的哦（左边那个是大学的o和大写i，右边是数字零和小写的L）。</p>
<h3 id="命名方法："><a href="#命名方法：" class="headerlink" title="命名方法："></a>命名方法：</h3><p>这里说两种最常用的命名方法，分别是驼峰命名法和下划线法。<br>驼峰命名法例如：printEmployeeSalay、getValueFromSQLServer、_httpListenAndServe等</p>
<p>下面改成下划线法：print_employee_salay,get_value_from_OS_Environment</p>
<p>我是比较喜欢在编程时使用驼峰命名法，在数据库中使用下划线，看你们喜欢。</p>
<p>不过上面命名并非最好的方法，你觉得是不是太长了，当写代码的时候如果没有自动补全会非常难受，当然也并非都是缺点，如果这是别人写的代码你可能一眼就知道是用来干什么的。</p>
<p>大部分情况应该要做到见名知意且简短，比如求和（sum），数值（val），圆周率（Pi）。</p>
<p>思考题：上面的两个标识符可以怎么简写呢？</p>
<p>新手写代码非常喜欢使用：a、abc、a1、a2这样子的标识符，这些标识符不应该乱用，应该仅仅用于循环的控制变量，不然代码行数一多，时间一长，你就会忘了哪个变量用来干什么。</p>
<h3 id="命名规范补充"><a href="#命名规范补充" class="headerlink" title="命名规范补充"></a>命名规范补充</h3><p>下面是不能使用的命名字符：auto、break、case	、char	、const、continue、default、do、double、else、enum、extern、float、for、goto、if、int、long、register、return、short、signed、sizeof、static、struct、switch、typedefunsigned、union、void、volatile、while、_Bool、_Complex、_Imaginary、inline、restrict、_Alignas、_Alignof、_Atomic、_Generic、_Noreturn、_Static_assert、_Thread_local</p>
<p>至于为什么不能使用，请继续学习并思考为什么不能使用这些词（从auto直到while）。</p>
<h2 id="空格的使用"><a href="#空格的使用" class="headerlink" title="空格的使用"></a>空格的使用</h2><p>空格一般用于某个元素的结束，比如int age，中间的空格表示了int的结束。</p>
<p>空格还可以用于提高代码的可读性，比如</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">food = noodle + pizza;</span><br><span class="line">food=noodle+pizza;</span><br></pre></td></tr></table></figure>
<p>第一行和第二行效果是完全一样的，但是明显第一行好看很多。</p>
<h1 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h1><ol>
<li>基本类型<blockquote>
<p>它们是算术类型，包括两种类型：整数类型和浮点类型。</p>
</blockquote>
</li>
<li>枚举类型<blockquote>
<p>它们也是算术类型，被用来定义在程序中只能赋予其一定的离散整数值的变量。</p>
</blockquote>
</li>
<li>void类型<blockquote>
<p>类型说明符 void 表明没有可用的值。</p>
</blockquote>
</li>
<li>派生类型<blockquote>
<p>它们包括：指针类型、数组类型、结构类型、共用体类型和函数类型。</p>
</blockquote>
</li>
</ol>
<h2 id="整数类型"><a href="#整数类型" class="headerlink" title="整数类型"></a>整数类型</h2><table>
<thead>
<tr>
<th>类型</th>
<th>储存大小</th>
<th>值范围</th>
</tr>
</thead>
<tbody><tr>
<td>char</td>
<td>1 字节</td>
<td>-128 到 127 或 0 到 255</td>
</tr>
<tr>
<td>unsigned char</td>
<td>1 字节</td>
<td>0 到 255</td>
</tr>
<tr>
<td>signed char</td>
<td>1 字节</td>
<td>-128 到 127</td>
</tr>
<tr>
<td>int</td>
<td>2 或 4 字节</td>
<td>-32,768 到 32,767 或 -2,147,483,648 到 2,147,483,647</td>
</tr>
<tr>
<td>unsigned int</td>
<td>2 或 4 字节</td>
<td>0 到 65,535 或 0 到 4,294,967,295</td>
</tr>
<tr>
<td>short</td>
<td>2 字节</td>
<td>-32,768 到 32,767</td>
</tr>
<tr>
<td>unsigned short</td>
<td>2 字节</td>
<td>0 到 65,535</td>
</tr>
<tr>
<td>long</td>
<td>4 字节</td>
<td>-2,147,483,648 到 2,147,483,647</td>
</tr>
<tr>
<td>unsigned long</td>
<td>4 字节</td>
<td>0 到 4,294,967,295</td>
</tr>
</tbody></table>
<blockquote>
<p>long float double等类型在不同平台不同编译器的储存大小可能不一样，下面实例使用sizeof运算符来得到对象或者类型的储存字节大小。</p>
</blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;limits.h&gt;</span></span></span><br><span class="line"> </span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;int 存储大小 : %lu \n&quot;</span>, <span class="keyword">sizeof</span>(<span class="type">int</span>));</span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;char 存储大小 : %lu \n&quot;</span>, <span class="keyword">sizeof</span>(<span class="type">char</span>));</span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;long 存储大小 : %lu \n&quot;</span>, <span class="keyword">sizeof</span>(<span class="type">long</span>));</span><br><span class="line">   </span><br><span class="line">   <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="浮点类型"><a href="#浮点类型" class="headerlink" title="浮点类型"></a>浮点类型</h2><p>下表列出了关于标准浮点类型的存储大小、值范围和精度的细节：</p>
<p>类型 | 储存大小 | 值范围 | 精度 </p>
<ul>
<li>| - | - |<br>float | 4 字节 | 1.2E-38 到 3.4E+38 | 6 位小数<br>double | 8 字节 | 2.3E-308 到 1.7E+308 | 15 位小数<br>long double | 16 字节 | 3.4E-4932 到 1.1E+4932 | 	19 位小数</li>
</ul>
<p>上面我们学会了用sizeof获得整形类型的储存大小，下面实例展示了获得float的储存空间和范围值</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;float.h&gt;</span></span></span><br><span class="line"> </span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;float 存储最大字节数 : %lu \n&quot;</span>, <span class="keyword">sizeof</span>(<span class="type">float</span>));</span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;float 最小值: %E\n&quot;</span>, FLT_MIN );</span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;float 最大值: %E\n&quot;</span>, FLT_MAX );</span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;精度值: %d\n&quot;</span>, FLT_DIG );</span><br><span class="line">   </span><br><span class="line">   <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="void类型"><a href="#void类型" class="headerlink" title="void类型"></a>void类型</h2><p>void指空类型，一般分三种：1）函数返回值为空，2）函数参数为空，3）指针指向void。后续章节会详细介绍这些类型的用法。</p>
<blockquote>
<p><em><strong>获得成就</strong></em><br>这是？基本语法！：初步掌握基本语法和结构</p>
</blockquote>
<hr>
<h1 id="变量和常量"><a href="#变量和常量" class="headerlink" title="变量和常量"></a>变量和常量</h1><p>上面学完了结构和数据类型并获得一项成就，是不是有点开心呢，那么你可以开始学习定义变量和使用运算符进行数据的操作了</p>
<p>在C语言中，如果你想使用某一个数据类型，比如int，你就需要创建一个变量来储存这个数据类型的值，这叫变量的定义或者变量的声明。</p>
<p>食用方法是：<code>type variable1 variable2 ...;</code></p>
<p>这里的type是上面说到的数据类型,下面是几个实例：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span>    i, j, k;</span><br><span class="line"><span class="type">char</span>   c, ch, input;</span><br><span class="line"><span class="type">float</span>  f, salary;</span><br><span class="line"><span class="type">double</span> d;</span><br></pre></td></tr></table></figure>

<p>既然声明可以储存值的变量，那么就可以把值赋给变量，继续列举几个实例</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> d = <span class="number">1</span>, i = <span class="number">2</span>;</span><br><span class="line"><span class="type">char</span> ch;</span><br><span class="line">ch = <span class="string">&#x27;a&#x27;</span>;</span><br></pre></td></tr></table></figure>
<p>赋值可以在声明的时候进行，或者先声明下一句再复制。<em><strong>注意要赋值后再使用这个变量</strong></em></p>
<h1 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h1><p>运算符是一种告诉编译器执行特定的数学或逻辑操作的符号，C语言内置了非常“丰（e）富（xin）”的运算符，包括以下类型的运算符：</p>
<ul>
<li>算术运算符</li>
<li>关系运算符</li>
<li>逻辑运算符</li>
<li>位运算符</li>
<li>赋值运算符</li>
<li>杂项运算符<br>下面我们先选最常用的算术、关系、逻辑、赋值运算符来讲。</li>
</ul>
<h2 id="算术运算符"><a href="#算术运算符" class="headerlink" title="算术运算符"></a>算术运算符</h2><p>算术运算符包括：+ - * &#x2F; %  ++ –<br>我寻思大部分人都学过数学，那么下面请跟着在编辑器里写一遍下面的实例，观察程序运行的结果，思考一下这些运算符都是什么意思。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"> </span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">   <span class="type">int</span> a = <span class="number">121</span>;</span><br><span class="line">   <span class="type">int</span> b = <span class="number">11</span>;</span><br><span class="line">   <span class="type">int</span> c ;</span><br><span class="line"> </span><br><span class="line">   c = a + b;</span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;使用 + - c 的值是 %d\n&quot;</span>, c );</span><br><span class="line">   c = a - b;</span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;使用 - - c 的值是 %d\n&quot;</span>, c );</span><br><span class="line">   c = a * b;</span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;使用 * - c 的值是 %d\n&quot;</span>, c );</span><br><span class="line">   c = a / b;</span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;使用 / - c 的值是 %d\n&quot;</span>, c );</span><br><span class="line">   c = a % b;</span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;使用 % - c 的值是 %d\n&quot;</span>, c );</span><br><span class="line">   c = a++;  <span class="comment">// 赋值后再加 1 ，c 为 21，a 为 22</span></span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;使用 ++ - c 的值是 %d\n&quot;</span>, c );</span><br><span class="line">   c = a--;  <span class="comment">// 赋值后再减 1 ，c 为 22 ，a 为 21</span></span><br><span class="line">   <span class="built_in">printf</span>(<span class="string">&quot;使用 -- - c 的值是 %d\n&quot;</span>, c );</span><br><span class="line"> </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="关系运算符"><a href="#关系运算符" class="headerlink" title="关系运算符"></a>关系运算符</h2><p>我们先假设两个变量a和b，值分别233，666。</p>
<table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody><tr>
<td>&#x3D;&#x3D;</td>
<td>检查两个操作数的值是否相等，如果相等则条件为真。</td>
<td>(A &#x3D;&#x3D; B) 不为真。</td>
</tr>
<tr>
<td>!&#x3D;</td>
<td>检查两个操作数的值是否相等，如果不相等则条件为真。</td>
<td>(A !&#x3D; B) 为真。</td>
</tr>
</tbody></table>
<blockquote>
<p>| 检查左操作数的值是否大于右操作数的值，如果是则条件为真。 | (A &gt; B) 不为真。<br>&lt; | 检查左操作数的值是否小于右操作数的值，如果是则条件为真。 | (A &lt; B) 为真。<br>&#x3D; | 检查左操作数的值是否大于或等于右操作数的值，如果是则条件为真。 | (A &gt;&#x3D; B) 不为真。<br>&lt;&#x3D; | 检查左操作数的值是否小于或等于右操作数的值，如果是则条件为真。 | (A &lt;&#x3D; B) 为真。</p>
</blockquote>
<h2 id="逻辑运算符"><a href="#逻辑运算符" class="headerlink" title="逻辑运算符"></a>逻辑运算符</h2><p>同上我们照样假设a和b，a为真和b为假，则：</p>
<table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>实例</th>
</tr>
</thead>
<tbody><tr>
<td>&amp;&amp;</td>
<td>称为逻辑与运算符。如果两个操作数都非零，则条件为真。</td>
<td>(A &amp;&amp; B) 为假。</td>
</tr>
<tr>
<td></td>
<td></td>
<td>称为逻辑或运算符。如果两个操作数中有任意一个非零，则条件为真。</td>
</tr>
<tr>
<td>!</td>
<td>称为逻辑非运算符。用来逆转操作数的逻辑状态。如果条件为真则逻辑非运算符将使其为假。</td>
<td>!a为假，!(A &amp;&amp; B) 为真。</td>
</tr>
</tbody></table>
<h2 id="赋值运算符"><a href="#赋值运算符" class="headerlink" title="赋值运算符"></a>赋值运算符</h2><p>这里因为没说位运算符所以这里只讲 <em><em>&#x3D; 、+&#x3D; 、-&#x3D; 、</em>&#x3D; 、&#x2F;&#x3D; 、%&#x3D;</em>*</p>
<p>&#x3D;是最简单的赋值操作符，用于把右边操作数赋给左边，比如：<code>c = a + b</code>，就是把a+b的值相加赋给c</p>
<p>c +&#x3D; a 相当于 c &#x3D; c + a，相信聪明的你能想到+&#x3D;是什么意思了吧。同理c *&#x3D; a 等于c &#x3D; c * a。那么其他的用法也相同。  </p>
<h1 id="第三章的思考题："><a href="#第三章的思考题：" class="headerlink" title="第三章的思考题："></a><em><strong>第三章的思考题：</strong></em></h1><p>用上面学到的知识，声明一个变量，接收一个年分，判断是否是闰年，并在命令行输出这一年是否是闰年。（解析和答案在下面评论区）</p>
<blockquote>
<p><em><strong>获得成就</strong></em><br>运算时间到！：初步掌握运算符并且能使用运算符处理一些算术问题。</p>
</blockquote>

    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>Wyatex
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://wyatex.online/C%E8%AF%AD%E8%A8%80/C-language-learn-3/" title="简单易懂的C语言-3">https://wyatex.online/C语言/C-language-learn-3/</a>
  </li>
  <li class="post-copyright-license">
      <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/tags/%E6%95%99%E7%A8%8B/" rel="tag"># 教程</a>
              <a href="/tags/C%E8%AF%AD%E8%A8%80/" rel="tag"># C语言</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/%E6%95%B0%E7%A0%81%E4%BA%A7%E5%93%81%E6%8E%A8%E8%8D%90/%E5%A4%A7%E5%AD%A6%E7%94%9F%E6%95%B0%E7%A0%81%E4%BA%A7%E5%93%81%E6%8E%A8%E8%8D%90/" rel="prev" title="大学生数码产品推荐">
                  <i class="fa fa-angle-left"></i> 大学生数码产品推荐
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/%E5%89%8D%E7%AB%AF/Html5%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-1/" rel="next" title="Html5学习笔记（1）">
                  Html5学习笔记（1） <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2019 – 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Wyatex</span>
  </div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script size="300" alpha="0.6" zIndex="-1" src="/lib/ribbon.js/dist/ribbon.min.js"></script>
  <script src="/lib/animejs/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="/lib/@next-theme/pjax/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="/lib/@fancyapps/ui/dist/fancybox/fancybox.umd.js" integrity="sha256-q8XkJ6dj5VwSvzI8+nATCHHQG+Xv/dAZBCgqmu93zOY=" crossorigin="anonymous"></script>
  <script src="/lib/lozad/dist/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="/lib/hexo-generator-searchdb/dist/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>



  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





</body>
</html>
